package com.sj.purchase.modules.helper.config;

import com.sj.purchase.modules.helper.config.task.OutBoundUniqueCodeTask;
import com.sj.purchase.util.Date2StrUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;

/**
 * @author yangrd
 * @date 2018/8/16
 **/
@Configuration
public class HelperScheduler {

    private OutBoundUniqueCodeTask task;

    private static Logger LOGGER = LoggerFactory.getLogger(HelperScheduler.class);

    @Autowired
    public HelperScheduler(OutBoundUniqueCodeTask task) {
        this.task = task;
    }

    /**
     * 每天4点
     */
    @Scheduled(cron = "0 0 4 * * ?")
    public void syncWMSData() {
        Date yesterday = DateUtils.addDays(new Date(),-1);
        String yesterdayStr = Date2StrUtils.str(yesterday);
        task.syncWMSData(yesterdayStr);
        LOGGER.info("{} 落宝 同步完成 ", yesterdayStr);
    }

    /**
     * 每个月的第一天
     */
    @Scheduled(cron = "0 0 4 1 * ?")
    public void cleaned2MonthsAgoData() {
        task.cleaned2MonthsAgoData();
    }

}
